//
//  MMEditorDetailViewController.m
//  zhihuDaily
//
//  Created by li  bo on 16/6/13.
//  Copyright © 2016年 cc. All rights reserved.
//

#import "MMEditorDetailViewController.h"
#import "MMEditorModel.h"
@interface MMEditorDetailViewController ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *indicatorView;

@property (nonatomic, copy) NSString *url;

@end

@implementation MMEditorDetailViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.view bringSubviewToFront:self.indicatorView];
    NSString *url = nil;


    self.title = [self.editorModel name];
    MMLog(@"%d",self.editorModel.id);
    url = [NSString stringWithFormat:@"http://news-at.zhihu.com/api/4/editor/%d/profile-page/ios", self.editorModel.id];


    self.url = url;

    self.webView.delegate = self;
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
}


- (void)webViewDidStartLoad:(UIWebView *)webView {
    [self.indicatorView startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self.indicatorView stopAnimating];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {


    if ([request.URL.absoluteString hasPrefix:@"http://news-at.zhihu.com/api/4/editor/"] || [request.URL.absoluteString hasPrefix:@"http://www.zhihu.com/people/"]) {
        return YES;
    }

    [[UIApplication sharedApplication] openURL:request.URL];
    return NO;
}


@end
